package com.idheima.Collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class doudizhu {
    //利用Collection工具类完成斗地主
    public static void main(String[] args) {
        //创建一副牌
        List<Card> cards = new ArrayList<>();
        String[] colors = {"♦", "♣", "♥", "♠"};
        String[] points = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        int size = 0;
        for (String point : points) {
            size++;
            for (String color : colors) {
                Card card = new Card(color, point, size);
                cards.add(card);
            }
        }
        cards.add(new Card("🤡", "小王", 60));
        cards.add(new Card("🃏", "大王", 61));
        System.out.println("一副牌：" + cards);


        //洗牌
        System.out.println("===========");
        Collections.shuffle(cards);
        System.out.println("洗牌后：" + cards);
        System.out.println("===========");
        //发牌一人17张
        ArrayList<Card> player1 = new ArrayList<>();
        ArrayList<Card> player2 = new ArrayList<>();
        ArrayList<Card> player3 = new ArrayList<>();
        for (int i = 0; i < cards.size()-3; i++) {
            if (i%3==0){
                player1.add(cards.get(i));
            }else if (i%3==1){
                player2.add(cards.get(i));
            }else {
                player3.add(cards.get(i));
            }
        }
        //底牌3张
        ArrayList<Card> dipai = new ArrayList<>();
        dipai.subList(cards.size()-3,cards.size());
        //看牌
        System.out.println("=======发牌=========");
        System.out.println("玩家1："+player1);
        System.out.println("玩家2："+player2);
        System.out.println("玩家3："+player3);
        System.out.println("底牌："+dipai);
        //整理牌
        System.out.println("=======整理牌后=========");
        Collections.sort(player1,(c1,c2)->c1.getSize()-c2.getSize());
        Collections.sort(player2,(c1,c2)->c1.getSize()-c2.getSize());
        Collections.sort(player3,(c1,c2)->c1.getSize()-c2.getSize());

        //地主拿牌和理牌
        player3.addAll(dipai);
        Collections.sort(player3,(c1,c2)->c1.getSize()-c2.getSize());
        System.out.println("======最终牌=======");
        System.out.println("玩家1："+player1);
        System.out.println("玩家2："+player2);
        System.out.println("地主："+player3);
    }
}
